package cn.xo68.ide.plugin.common.service;

import cn.xo68.ide.plugin.common.domain.GitSetting;
import cn.xo68.ide.plugin.common.domain.ProjectSetting;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.util.xmlb.XmlSerializerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

@State(name = "WxToolSuiteSetting", storages = @Storage("wx-tool-suite-setting.xml"))
public class Settings  implements PersistentStateComponent<Settings> {

    public static Settings getInstance() {
        return ServiceManager.getService(Settings.class);
    }

    private GitSetting gitSetting;
    private ProjectSetting projectSetting;

    public GitSetting getGitSetting() {
        return gitSetting;
    }

    public void setGitSetting(GitSetting gitSetting) {
        this.gitSetting = gitSetting;
    }

    public ProjectSetting getProjectSetting() {
        return projectSetting;
    }

    public void setProjectSetting(ProjectSetting projectSetting) {
        this.projectSetting = projectSetting;
    }

    public Settings() {
        init();
    }

    public void init(){
        gitSetting=new GitSetting();
        projectSetting=new ProjectSetting();
    }

    @Nullable
    @Override
    public Settings getState() {
        return this;
    }

    @Override
    public void loadState(@NotNull Settings state) {
        // 覆盖初始配置
        XmlSerializerUtil.copyBean(state, this);
    }
}
